<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>表单 -项目</title>
		<link rel="icon" href="../../../favicon.ico" type="image/ico">
		<link href="../../../css/bootstrap.min.css" rel="stylesheet">
		<link href="../../../css/materialdesignicons.min.css" rel="stylesheet">
		<link href="../../../css/style.min.css" rel="stylesheet">
	</head>

	<body>
		<div class="container-fluid p-t-15">

			<div class="row">
				<div class="col-lg-12">
					<div class="card">
						<div class="card-body">

							<form class="site-form">
								<div class="form-group">
									<label for="projectname">项目名称</label>
									<input type="text" class="form-control" name="projectname" id="projectname" />
								</div>

								<div class="form-group">
									<label for="project_company">合作公司</label>
									<input type="text" class="form-control" name="project_company" id="project_company" />
								</div>


								<div class="form-group">
									<label for="project_price">项目资金</label>
									<input type="text" class="form-control" name="project_price" id="project_price" />
								</div>

								<div class="form-group">
									<label for="project_order">项目订单</label>
									<select class="form-control" id="project_order" name="project_order" size="1">
										<option value="0">请选择</option>
										<option value="1">选项 #1</option>
										<option value="2">选项 #2</option>
										<option value="3">选项 #3</option>
									</select>
								</div>

								<div class="form-group">
									<label for="project_status">项目状态</label>
									<input type="text" class="form-control" name="project_status" id="project_status" />
								</div>

								<div class="form-group">
									<label for="start_date">开始时间</label>
									<input class="form-control js-datepicker m-b-10" type="text" id="start_date" name="start_date" placeholder="yyyy-mm-dd"
									 value="" data-date-format="yyyy-mm-dd" />
								</div>

								<div class="form-group">
									<label for="end_date">结束时间</label>
									<input class="form-control js-datepicker m-b-10" type="text" id="end_date" name="end_date" placeholder="yyyy-mm-dd"
									 value="" data-date-format="yyyy-mm-dd" />
								</div>


								<button id="submit2" class="btn btn-primary">保存</button>

						</div>
						</form>

					</div>
				</div>
			</div>

		</div>

		</div>

		<script type="text/javascript" src="../../../js/jquery.min.js"></script>
		<script>
			var projectId = ";"
			$(function() {
				var url = location.search //获取url中"?"符后的字串 ('?modFlag=business&role=1')
				var theRequest = new Object()
				if (url.indexOf('?') != -1) {
					var str = url.substr(1) //substr()方法返回从参数值开始到结束的字符串；
					var strs = str.split('&')
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
					}
					projectId = theRequest.projectId;
					$(" input[ name='projectname' ] ").val(decodeURI(theRequest.projectName));
					 $("#project_order").val(theRequest.projectOrder);
					 $(" input[ name='project_status' ] ").val(theRequest.statusId);
				$(" input[ name='project_company' ] ").val(decodeURI(theRequest.projectCompany));
					 $(" input[ name='project_price' ] ").val(theRequest.projectPrice);
					 $(" input[ name='start_date' ] ").val(theRequest.startTime);
					$(" input[ name='end_date' ] ").val(theRequest.endTime);

				}
			});
			$("#submit2").click(function() {
				console.log(projectId);
				var projectName = $(" input[ name='projectname' ] ").val();
				var projectOrderId = $("#project_order").val();
				var statusId = $(" input[ name='project_status' ] ").val();
				var projectCompany = $(" input[ name='project_company' ] ").val();
				var projectPrice = $(" input[ name='project_price' ] ").val();
				var startTime = $(" input[ name='start_date' ] ").val();
				var endTime = $(" input[ name='end_date' ] ").val();

				$.ajax({
					url: "http://www.oa.com/oa/add",
					type: "post",
					data: {
						"projectId":projectId,
						"projectName": projectName,
						"projectOrderId": projectOrderId,
						"statusId": statusId,
						"projectCompany": projectCompany,
						"projectPrice": projectPrice,
						"startTime": startTime,
						"endTime": endTime
					},
					dataType: "json",
					async: false,
					success: function(result) {
						//result是服务端返回的数据
						if (result.status == 200) {
							alert("添加成功！")
							location.href = "project_list.html";
						} else {
							alert("添加失败");
						}
					},
					error: function() {
						alert("请求失败!");
					}
				});

			})
		</script>

		<!--时间选择插件-->
		<script src="../../../js/bootstrap-datetimepicker/moment.min.js"></script>
		<script src="../../../js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
		<script src="../../../js/bootstrap-datetimepicker/locale/zh-cn.js"></script>

		<!--日期选择插件-->
		<script src="../../../js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
		<script src="../../../js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
		<script type="text/javascript" src="../../../js/main.min.js"></script>
	</body>
</html>
